﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace TQ.Sharepoint.Webparts.TwitterWebpart
{
    [ToolboxItemAttribute(false)]
    public class TwitterWebpart : Microsoft.SharePoint.WebPartPages.WebPart
    {
        private string _query = Str.DefaultQuery;
        private string _maxTweets = Str.DefaultMaxTweets;
        private string _tweetsPerPage = Str.DefaultTweetsPerPage;
        [WebPartStorage(Storage.Personal)]
        public string Query
        {
            get { return _query; }
            set { _query = value; }
        }

        [WebPartStorage(Storage.Personal)]
        public string MaxTweets
        {
            get { return _maxTweets; }
            set { _maxTweets = value; }
        }

         [WebPartStorage(Storage.Personal)]
        public string TweetsPerPage
        {
            get { return _tweetsPerPage; }
            set { _tweetsPerPage = value; }
        }

       
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/TQ.Sharepoint.Webparts/TwitterWebpart/TwitterWebpartUserControl.ascx";

        protected override void CreateChildControls()
        {
            var control = (TwitterWebpartUserControl)Page.LoadControl(_ascxPath);
            control.Query = Query;
            control.MaxTweets = MaxTweets;
            control.TweetsPerPage = TweetsPerPage;
            Controls.Add(control);
        }

        public override ToolPart[] GetToolParts()
        {
            var allToolParts = new ToolPart[3];
            var standardToolParts = new WebPartToolPart();
            var customToolParts = new CustomPropertyToolPart();

            allToolParts[0] = new CustomToolpart();
            allToolParts[1] = customToolParts;
            allToolParts[2] = standardToolParts;

            return allToolParts;
        }
    }
}
